package com.atguigu.gmall.product.mapper;

import com.atguigu.gmall.model.product.SkuInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * sku mapper 映射
 */
@Mapper
public interface SkuInfoMapper extends BaseMapper<SkuInfo> {
    /**
     * 扣减库存
     * @param skuId
     * @param skuNum
     * @return
     */
    @Update("UPDATE sku_info SET stock = stock - #{skuNum} WHERE id = #{skuId} AND stock >= #{skuNum}")
     int deductSku(@Param("skuId") Long skuId, @Param("skuNum") Integer skuNum);

    /**
     * 回滚库存
     * @param skuId
     * @param skuNum
     * @return
     */
    @Update("update sku_info set stock = stock + #{skuNum} where id = #{skuId}")
    int rollBackStock(@Param("skuId") Long skuId, @Param("skuNum") Integer skuNum);
}
